package org.xhy.circuitbreaker.config;

import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.xhy.circuitbreaker.CircuitBreakerBeanPostProcessor;
import org.xhy.circuitbreaker.CircuitBreakerController;
import org.xhy.circuitbreaker.ICircuitBreakerController;
import org.xhy.circuitbreaker.alert.AlertService;
import org.xhy.circuitbreaker.alert.DefaultAlert;

/**
 * @description:
 * @gitee: https://gitee.com/XhyQAQ
 * @copyright: B站: https://space.bilibili.com/152686439
 * @Author: Xhy
 * @CreateTime: 2024-06-06 19:14
 */
@Configuration
public class CircuitBreakerConfig {

    @Bean
    public CircuitBreakerProperties circuitBreakerProperties(){
        return new CircuitBreakerProperties();
    }

    @Bean("defaultAlert")
    public DefaultAlert alertService(){
        return new DefaultAlert();
    }

    @Bean
    @ConditionalOnMissingBean(CircuitBreakerController.class)
    public ICircuitBreakerController iCircuitBreakerController(CircuitBreakerProperties circuitBreakerProperties){
        return new CircuitBreakerController(circuitBreakerProperties);
    }

    @Bean
    public CircuitBreakerBeanPostProcessor circuitBreakerBeanPostProcessor(ICircuitBreakerController iCircuitBreakerController){
        return new CircuitBreakerBeanPostProcessor(iCircuitBreakerController);
    }
}
